package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.ProductionMaterialReturnDetail;
import com.pureut.storage.dto.ProductionMaterialReturnDetailDto;
import com.pureut.storage.dto.SalesReturnDetailDto;
import com.pureut.storage.mapper.ProductionMaterialReturnDetailMapper;
import com.pureut.storage.service.ProductionMaterialReturnDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/***
 * 销售退货实现层
 * Author:C
 * Date:2023/01/29 10:39
 * @DESC
 */
@Service
public class ProductionMaterialReturnDetailServiceImpl extends ServiceImpl<ProductionMaterialReturnDetailMapper, ProductionMaterialReturnDetail> implements ProductionMaterialReturnDetailService {

    @Resource
    ProductionMaterialReturnDetailMapper productionMaterialReturnDetailMapper;


    /**
     * 生产退料明细列表
     *
     * @param id
     * @return
     */
    @Override
    public List<ProductionMaterialReturnDetailDto> getProductionDetail(long id) {
        //明细状态
        List<SysDictData> statusArray = DictUtils.getDictCache("miscellaneous_receipt_detail_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<ProductionMaterialReturnDetailDto> productionDetail = productionMaterialReturnDetailMapper.getProductionDetail(id);

        for (ProductionMaterialReturnDetailDto entity : productionDetail) {
            entity.setStatusDict(statusMap.get(entity.getStatus()));
        }
        return productionDetail;
    }
}
